package com.moli.iov.handle.alarm.mq.kafka;

import com.moli.iov.handle.alarm.model.dto.AlarmDto;
import com.moli.iov.producer.KafkaProducerServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * <p>
 *  kafka生产者  报警通知
 * </p>
 *
 * @author: zql
 * @Date: 2018/11/28 14:34
 */
@Component("kafkaProducer")
public class KafkaProducer {

    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private KafkaProducerServer kafkaProducerServer;

    @Value("${kafak.alarm.notice.topic}")
    private String topic;

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    /**
     * 推送数据
     * @param alarmDto
     */
    public void send(AlarmDto alarmDto){
        taskExecutor.execute(()->{
            logger.info("[报警通知] Kafka推送数据 topic:{} 参数：{}", topic, alarmDto);
            Map<String, Object> res = kafkaProducerServer.sndMesForTemplate(topic,
                                                                            alarmDto.getVin(),
                                                                            alarmDto);
            logger.info("[报警通知] Kafka 推送数据 topic:{} 结果返回：{}", topic, res);
        });
    }
}
